package com.example.android1;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.android1.mytaxi.splash.SplashActivity;
import com.example.android1.osstruts.OsStructsActivity;
import com.example.android1.osstruts.logs.ebus.MyBusEvent;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
//import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {
    private MainActivity mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        mContext = this;
        initViews();

    }





    private void initViews() {
        findViewById(R.id.btn_my_taxi).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(mContext, SplashActivity.class));
            }
        });
        findViewById(R.id.btn_os_structs).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(mContext, OsStructsActivity.class));
            }
        });
        findViewById(R.id.btn_event_bus).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new MyBusEvent(""));
            }
        });

//        ButterKnife.bind(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);//3.注册
    }
    @Override
    protected void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);//3.反注册
    }
    //2.订阅者,一定要带上注解，表示是订阅者，表示onMessageEvent在主线程中完成
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MyBusEvent event) {
        Toast.makeText(this, event.message, Toast.LENGTH_LONG).show();
    }

}